package com.flyduck.vueshop.user.remote.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.flyduck.vueshop.common.core.utils.BeanUtils;
import com.flyduck.vueshop.user.entity.AppAddress;
import com.flyduck.vueshop.user.mapper.AppAddressMapper;
import com.flyduck.vueshop.user.remote.service.RemoteAddressService;
import com.flyduck.vueshop.user.vo.RemoteAddressRespVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 * RemoteAddressServiceImpl
 * </p>
 *
 * @author flyduck
 * @since 2024-07-22
 */
@Slf4j
@Service
public class RemoteAddressServiceImpl implements RemoteAddressService {

    @Resource
    private AppAddressMapper appAddressMapper;

    @Override
    public RemoteAddressRespVO getDefaultAddressByUserId(Long userId) {
        AppAddress appAddress = appAddressMapper.selectOne(
                new LambdaQueryWrapper<AppAddress>()
                        .eq(AppAddress::getUserId, userId)
                        .eq(AppAddress::getIsDefault, true)
        );
        return BeanUtils.toBean(appAddress,RemoteAddressRespVO.class);
    }

    @Override
    public RemoteAddressRespVO getAddressById(Long id) {
        AppAddress appAddress = appAddressMapper.selectById(id);
        return BeanUtils.toBean(appAddress,RemoteAddressRespVO.class);
    }
}
